Ext.define('AmpleHarvest.objects.groups.forms.cRequest',
{
   extend         : 'Ext.form.Panel',
   alias			: 'widget.ampleharvest-objects-groups-forms-crequest',
   requires    :
   [
         "Ext.form.field.Hidden", 
         "Ext.form.field.Text",
         "Ext.form.field.Checkbox", 
         "Ext.form.field.TextArea",
         "Ext.form.field.ComboBox",
         "AmpleHarvest.objects.classification.cPanel"
   ],
   uses        : [
   // 'DarkOwl.User_Manager.Windows.Setup.cCreateDB',
   ],
   labelWidth     : 93,
   buttonAlign    : 'right',
   frame       : true,
   timeout        : 1000,
   bodyStyle      : 'padding:5px 5px 0',
   autoWidth      : true,
   autoHeight     : true,
   standardSubmit : false,
   defaultType    : 'textfield',

   initComponent  : function()
   {
      var obj_This = this;

      this.buttons =
      [
            {
               text     : 'Cancel',
               autoWidth   : true,
               disabled : false,
               handler     : function()
               {
                  obj_This.ownerCt.destroy();
               }
            },
            {
               text     : 'Submit',
               formBind : true,
               disabled : true,
               scope    : this,
               autoWidth   : true,
               handler     : function()
               {

                  obj_This.getForm().submit(
                  {
                     url      : obj_config.C_STR_EXTERNAL_PATH+'/rest/group/group.php',
                     waitMsg  : 'Submiting Your Group Request',
                     method   : "put",
                     success  : this.submit_Success,
                     failure  : this.submit_Fail,
                     scope : this
                  }
                  );
               }
            }
      ];
      
      this.callParent();
      
      this.m_str_UserName = obj_config.user.userName;

      this.m_obj_Classification = Ext.create("AmpleHarvest.objects.classification.cPanel",
            {
               m_bool_Editable            : true,
               m_str_ClassificationName   : 'classification',
               m_str_SCIName           : 'sci',
               m_str_DistroName        : 'distro'
            }
      );

      this.add(this.m_obj_Classification);

      this.m_obj_Form_UserID = Ext.create("Ext.form.field.Hidden",
      {
         name     : 'requester',
         readOnly : true,
         allowBlank  : false
      }
      );
      this.m_obj_Form_UserID.setValue(obj_config.user.id);
      this.add(this.m_obj_Form_UserID);

      this.add(Ext.create("Ext.form.field.Text",
      {
         fieldLabel  : "Group Name",
         name     : 'name',
         inputType   : "textfield",
         readOnly : false,
         anchor      : '100%',
         allowBlank  : false
      }
      ));
      
      this.add(Ext.create("Ext.form.field.TextArea",
      {
         fieldLabel  : "Description",
         name     : "description",
         inputType   : "textfield",
         readOnly : false,
         anchor      : '100%',
         allowBlank  : false
      }
      ));

      this.add(Ext.create("Ext.form.field.TextArea",
      {
         fieldLabel  : "Justification",
         name     : "justification",
         allowBlank  : false,
         allowBlank  : false,
         readOnly : false,
         anchor      : '100%'
      }
      ));

      this.add(Ext.create("Ext.panel.Panel",
      {
         frame : true,
         border   : "0",
         html  : '* Field labels "<span style="color:red"><u>red</u></span>" are required, Also you must select either Whole Site or Enter Keywords.'
      }
      ));
      
   },

   submit_Success : function(str_Function, mix_Arg)
   {
      this.ownerCt.close();

      Ext.MessageBox.alert("Success", "Your Request has been sent.", close);
   },

   submit_Fail    : function(str_Function, mix_Arg)
   {
      Ext.MessageBox.alert("Error", mix_Arg.result.errors.msg, close);
   }
}
);
